﻿@model IList<DataAccess.CasoRotativo>
@{
    ViewBag.Title = "Rotativo";    
}
<div class="centralcontainer rounded-corners">
    <!-- BODY -->
    <table width="100%" cellpadding="20px">
        <tr>
            <td>
                <h1 class="rounded-corners">
                    Rotativo
                </h1>
                <!-- MENSAJERIA -->
                <div id="DivMensajeria" style="display: none;">
                    @Html.Partial("Fail", "")
                    @Html.Partial("Warning", "")
                    @Html.Partial("Success", "")
                </div>
                <div class="divformulario rounded-corners" style="margin-bottom: 10px">
                    <h2 class="rounded-corners">
                        Insertar nueva imagen
                    </h2>
                    <form action="@Url.Action("InsertImagenGaleria")" enctype="multipart/form-data" method="post">
                    <input type="hidden" value="@ViewBag.idCaso" name="idCaso"/>
                    <input type="file" required="required" name="imagen" />
                    <label class="tahoma12">
                        Orden:
                    </label>
                    <input type="number" required="required" min="1" max="100" name="orden" />
                    <input type="submit" value="Guardar" class="botonPequeno tahoma14" style="border-width: 0px;
                        margin-left: 5px;" />
                    </form>
                </div>
                <div class="divformulario rounded-corners">
                    @if (Model.Count > 0)
                    {
                        <div style="position: relative;">
                            @foreach (var rot in Model)
                            {
                                <div class="thumb shadows">
                                    <img src="@Url.Action("GetImagen", "Imagen", new { idImagen = rot.IdImagen })" alt="ARRB" />
                                    <form action="@Url.Action("DeleteImagenRotativo")" enctype="application/x-www-form-urlencoded" method="post">
                                    <input type="hidden" value="@rot.Id" name="idImagen" />
                                    <img src="@Url.Content("~/Content/img/Botones/xeliminar.jpg")" alt="arrb" class="deleteImagen" style="cursor:pointer;"/>
                                    </form>
                                    <div class="clean-floats">
                                    </div>
                                    <h3 class="tahoma12">
                                        Orden:
                                    </h3>
                                    <form action="@Url.Action("UpdateOrden")" enctype="application/x-www-form-urlencoded" method="post" class="cambiarOrden">
                                    <input type="hidden" value="@rot.Id" name="idImagen" />
                                    <input type="number" required="required" min="1" max="100" name="orden" value="@rot.Orden"/>
                                    <input type="submit" value="Guardar" class="botonPequeno tahoma14" style="border-width: 0px;
                                        margin-left: 5px;" />
                                    </form>
                                </div>
                            }
                        </div>
                    }
                    else
                    {
                        @Html.Partial("Warning", "No se han asociado imagenes a la galeria.")
                    }
                </div>
            </td>
        </tr>
    </table>
</div>
<!-- CONFIRMATION -->
<div id="dialog-confirm" style="display: none;" title="¿Eliminar permanentemente?">
    <p>
        ¿Esta seguro que desea eliminar esta imagen del sistema? Esta acción no se puede
        revertir.
    </p>
</div>
@section header{
    <script type="text/javascript" language="javascript">
        $(function () {
            $('.message').hide();
            $('#DivMensajeria').show();
            $('.divformulario').find('.warning').show();

            $('.deleteImagen').click(function () {
                var form = $(this).parent();
                $("#dialog-confirm").dialog({
                    resizable: false,
                    modal: true,
                    buttons: {
                        'Eliminar': function () {
                            $("#Loader").show();
                            $.post(form.attr('action'), form.serialize(), function (response) {
                                if (response.success == true) {
                                    form.parent().fadeOut();
                                    ShowSuccess(response.mensaje);
                                }
                                else {
                                    ShowFail(response.mensaje);
                                }
                                $("#Loader").hide();
                            });
                            $(this).dialog('close');
                        },
                        'Cancelar': function () {
                            $(this).dialog('close');
                        }
                    }
                });
                return false;
            });

            $('.cambiarOrden').submit(function () {
                $.post($(this).attr('action'), $(this).serialize(), function (response) {
                    if (response.success == true) {
                        ShowSuccess(response.mensaje);
                    }
                    else {
                        ShowFail(response.mensaje);
                    }
                    $("#Loader").hide();
                });
                return false;
            });

        });
    </script>
}
@section navegacion{
    <a href="@Url.Action("Index", "Home")" class="tahoma14 black">Home </a>&nbsp;&gt;&nbsp;
    <a href="@Url.Action("Index")" class="tahoma14 black">Casos </a>&nbsp;&gt;&nbsp;
    <label class="tahoma14 black">
        Galeria
    </label>
}
